//! 标识符有时候也是表达式

use crate::lexer::token::Token;
use crate::parser::expression::Expression;
use crate::parser::node::{Node, NodeRoot};
use std::ops::Deref;

#[derive(Debug, Clone)]
pub struct Identifier {
    node: NodeRoot,
    token: Token,
    value: String,
}

impl Identifier {
    pub fn new(token: Token, value: String) -> Self {
        let node = NodeRoot::new(token.literal_ref().to_string(), "Identifier".to_string());
        Self { node, token, value }
    }
}

impl Expression for Identifier {
    fn cast_to_node(&self) -> &dyn Node {
        &self.node
    }
}

impl Deref for Identifier {
    type Target = NodeRoot;

    fn deref(&self) -> &Self::Target {
        &self.node
    }
}
